<template>
  <div>
    <el-drawer :visible.sync="show" direction="btt" size="60%" :before-close="handleClose" :with-header="false">
      <h3>全部评论</h3>
      <Comcard  v-if="showup" :comment="this.$store.state.movie.upComment"></Comcard>
      <Comcard :comment="allComment"></Comcard>
      <el-button type="info" icon="el-icon-edit" circle class="com" @click="dialogVisible = true"></el-button>
    </el-drawer>
    <el-dialog title="写评价" :visible.sync="dialogVisible" width="80%">
      <el-form :model="commentForm" :rules="rules" ref="CommentRef">
        <el-form-item label="评分" prop="score">
          <el-rate v-model="commentForm.score" show-text ></el-rate>
        </el-form-item>
        <el-form-item label="评价" prop="content">
          <el-input type="textarea" v-model="commentForm.content"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
    <el-button @click="reset">取 消</el-button>
    <el-button type="primary" @click="addComment">确 定</el-button>
  </span>
    </el-dialog>
  </div>
</template>

<script>
import Comcard from "./Comcard";
export default {
  name: "comdrawer",
  components: {Comcard},
  data(){
    return{
      dialogVisible:false,
      commentForm:{
        score:null,content:'',Id:this.$route.params.id,
        uid:window.localStorage.getItem('id'),type:1
      },
      rules:{
        score:[{required: true,message: '请评分',trigger: 'change'}],
        content:[{required:true,message:'请填写评价',trigger:'blur'}]},
      showup:false,

    }
  },
  props:{
    allComment:{required:true},
    show:{type:Boolean,require:true}
  },
  methods:{
    handleClose(){
      this.$emit('showDrawer')
    },
    reset(){
this.dialogVisible=!this.dialogVisible
        this.$refs.CommentRef.resetFields()
    },
    addComment(){
      this.$refs.CommentRef.validate( async (valid) => {
        if (valid) {
          this.$store.dispatch('movie/movAddComment',this.commentForm)
          this.showup=true
          this.reset()
        } else {
          return this.$message.error('请填写评论')
        }
      })
    }
  }
}
</script>

<style scoped>
h3{
  margin: 10px;
}
/deep/ .el-drawer.btt{
  overflow: scroll;
  border-radius: 5% 5% 0% 0%
}
.com{
  position: fixed;
  bottom: 20px;
  right: 20px;
}
</style>
